package com.woniu.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.common.dto.MySkuOrderDto;
import com.woniu.common.dto.SkuDto;
import com.woniu.common.util.PageParam;
import com.woniu.common.util.ResponseData;
import com.woniu.product.mapper.TOrderDetailMapper;
import com.woniu.product.pojo.TOrderDetail;
import com.woniu.product.service.TOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author zyq
* @description 针对表【t_order_detail(订单详细)】的数据库操作Service实现
* @createDate 2024-05-21 20:19:38
*/
@Service
public class TOrderDetailServiceImpl extends ServiceImpl<TOrderDetailMapper, TOrderDetail>
    implements TOrderDetailService{
    @Autowired
    private TOrderDetailMapper orderDetailMapper;

    @Override
    public ResponseData<?> queryDetailByPhone(String phone) {
        List<MySkuOrderDto> mySkuOrderDtos = orderDetailMapper.queryDetailByPhone(phone);
        return new ResponseData<>().ok(mySkuOrderDtos);
    }

    @Override
    public ResponseData<?> queryOrders(PageParam<MySkuOrderDto> pageParam) {
        // 创建Page对象，第一个参数是当前页，第二个参数是每页的数量
        Page<MySkuOrderDto> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        // 使用 Page 对象进行分页查询
        IPage<MySkuOrderDto> mySkuOrderDtoIPage = orderDetailMapper.queryOrders(page, pageParam.getParam().getUserTelephone());

        return new ResponseData<>().ok(mySkuOrderDtoIPage);
    }

    @Override
    public ResponseData<?> queryOrdersOk(PageParam<MySkuOrderDto> pageParam) {
        // 创建Page对象，第一个参数是当前页，第二个参数是每页的数量
        Page<MySkuOrderDto> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        // 使用 Page 对象进行分页查询
        IPage<MySkuOrderDto> mySkuOrderDtoIPage = orderDetailMapper.queryOrdersOk(page, pageParam.getParam().getUserTelephone());

        return new ResponseData<>().ok(mySkuOrderDtoIPage);
    }

    @Override
    public ResponseData<?> queryhostSks() {
        List<MySkuOrderDto> mySkuOrderDtos = orderDetailMapper.queryhostSks();
        return new ResponseData<>().ok(mySkuOrderDtos);
    }

    @Override
    public ResponseData<?> queryTeseSku(String phone) {
        MySkuOrderDto mySkuOrderDto = orderDetailMapper.queryTeseSku(phone);
        if (mySkuOrderDto != null) {
            List<SkuDto> skuDtos = orderDetailMapper.queryTeseBySkuId(mySkuOrderDto.getItemId().longValue());
            return new ResponseData<>().ok(skuDtos);
        }
        List<MySkuOrderDto> mySkuOrderDtos = orderDetailMapper.queryhostSks();
        return new ResponseData<>().ok(mySkuOrderDtos);
    }
}




